import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../page/login_test.dart';
import 'package:edge_insert_observer/edge_insert_observer.dart';

class RtextField extends StatefulWidget {
  @override
  _RtextFieldState createState() => _RtextFieldState();
}

class _RtextFieldState extends State<RtextField>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  FocusNode _focusNode1 = FocusNode();
  bool show1 = false;
  
  FocusNode _focusNode2 = FocusNode();
  bool show2 = false;
  @override
  void initState() {
    _focusNode1.addListener(() {
      // TextField has lost focus
      print(_focusNode1.hasFocus ? '获的焦点111111' : '失去焦点11111');
      setState(() {
        show1 = _focusNode1.hasFocus;
      });
    });
    _focusNode2.addListener(() {
      // TextField has lost focus
      print(_focusNode1.hasFocus ? '获的焦点22222' : '失去焦点22222');
      setState(() {
        show2 = _focusNode2.hasFocus;
      });
    });
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    double bottomInsert = MediaQuery.of(context).viewInsets.bottom;
    // 通过判定 bottomInsert 的值来判定键盘的弹出和隐藏
    print(bottomInsert > 0 ? '弹出' : '收起');

    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text('带X框'),
      ),
      body: Column(
        children: <Widget>[
            // 用户名文本框
  // LoginTextField userNameTextField() {
  //   return LoginTextField(
  //       placeholder: "用户名",
  //       prefixIconSelected: userNameValid,
  //       prefixIconNormalImageName: 'assets/images/login/login_username_gray.png',
  //       prefixIconSelectedImageName: 'assets/images/login/login_username_blue.png',
  //       autofocus: shouldAutofocusUserNameTextField,
  //       keyboardType: TextInputType.text,
  //       controller: _usernameController,
  //       textInputAction: TextInputAction.next,
  //       focusNode: usernameFocusNode,
  //       onSubmitted: (text) {
  //         print("current userName:" + text);
  //         if (null == currentFocusNode) {
  //           currentFocusNode = FocusScope.of(context);
  //         }
  //         currentFocusNode.requestFocus(passwordFocusNode);
  //       });
  // }
          // ,
          Container(
            child: 
            

            textFieldBgWidget(
                show1,
                MediaQuery.of(context).size.width,
                40,
                TextField(
                  style: TextStyle(
                    fontSize: 14.0,
                    color: Colors.black,
                  ),
                  maxLines: 1,
                  autofocus: false,
                  inputFormatters: [LengthLimitingTextInputFormatter(30)],
                  textInputAction: TextInputAction.search,
                  focusNode: _focusNode1,
                  onSubmitted: (String text) {
                    print(text);
                    FocusScope.of(context).requestFocus(FocusNode());
                  },
                  decoration: InputDecoration(
                    hintText: '请输入要年纪',
                    filled: false,
                    // fillColor: Colors.white,
                    border: InputBorder.none,
                    hintStyle: TextStyle(color: Colors.grey, fontSize: 14),
                    contentPadding: const EdgeInsets.symmetric(vertical: 2.0),
                  ),
                  onChanged: (String str) {
                    print(str);
                    //赋值
                  },
                )),
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            child: textFieldBgWidget(
                show2,
                MediaQuery.of(context).size.width,
                40,
                TextField(
                  style: TextStyle(
                    fontSize: 14.0,
                    color: Colors.black,
                  ),
                  maxLines: 1,
                  autofocus: false,
                  inputFormatters: [LengthLimitingTextInputFormatter(30)],
                  textInputAction: TextInputAction.search,
                  focusNode: _focusNode2,
                  onSubmitted: (String text) {
                    print(text);
                    FocusScope.of(context).requestFocus(FocusNode());
                  },
                  decoration: InputDecoration(
                    hintText: '请输入要查找的公司名称',
                    filled: false,
                    // fillColor: Colors.white,
                    border: InputBorder.none,
                    hintStyle: TextStyle(color: Colors.grey, fontSize: 14),
                    contentPadding: const EdgeInsets.symmetric(vertical: 2.0),
                  ),
                  onChanged: (String str) {
                    print(str);
                    //赋值
                  },
                )),
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            child: ITextField(
              // keyboardType: ITextInputType.text,
              hintText: '请输入手机号',
              hintStyle: TextStyle(color: Colors.grey),
              textStyle: TextStyle(color: Colors.black),
              fieldCallBack: (content) {
                print(content);
              },
            ),
          ),
          SizedBox(
            height: 10,
          ),
           Container(
            child: ITextField(
              // keyboardType: ITextInputType.text,
              hintText: '请输入手机号11111',
              hintStyle: TextStyle(color: Colors.grey),
              textStyle: TextStyle(color: Colors.black),
              fieldCallBack: (content) {
                print(content);
              },
            ),
          ),
          Container(
            child: FlatButton(
              color: Colors.blue,
              padding: EdgeInsets.all(0),
              child: Text(
                '点击',
                style: TextStyle(color: Colors.red, fontSize: 20),
              ),
              onPressed: () {},
            ),
          ),
      
       
        ],
      ),
    );
  }
}
